package com.gitee.devinx3.mrg.message;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

@Component
public class MessageHandler {

    private Source source;

    private static final Logger logger = LoggerFactory.getLogger(MessageHandler.class);

    @Autowired
    public MessageHandler(Source source){
        this.source = source;
    }

    public void publish(MsgCommand msgCommand){
       logger.debug("Sending Kafka message {} for Organization Id: {}", msgCommand.getAction(), msgCommand.getId());
        // 当准备发送消息时，使用 Source 类中定义的通道的 send() 方法
        source.output().send(MessageBuilder.withPayload(msgCommand).build());
    }
}